import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.util.Bytes;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class HBase_test {

        private static Configuration conf = HBaseConfiguration.create();
        private static Admin admin;
        private static Connection connection = null;

        static {
            //HBase Master地址，在hbase-site.xml中配置
            conf.set("hbase.rootdir", "hdfs://hp1:9000/hbase");
            //ZooKeeper三个服务器地址
            conf.set("hbase.zookeeper.quorum", "hp1,hp2,hp3");

            try {
                connection = ConnectionFactory.createConnection(conf);
                admin = connection.getAdmin();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void createTable(String tableName) throws IOException {

            //通过管理员对象创建表
            HTableDescriptor hTableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
            //给表添加列族
            HColumnDescriptor f1 = new HColumnDescriptor("f1");
            HColumnDescriptor f2 = new HColumnDescriptor("f2");
            //将两个列族设置到 创建的表中
            hTableDescriptor.addFamily(f1);
            hTableDescriptor.addFamily(f2);
            //创建表
            admin.createTable(hTableDescriptor);
            //关闭连接
            admin.close();
            connection.close();
            System.out.println("创建表成功");
        }



}
